package dao.Implementation;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import Donnees.Transport;
import Util.HibernateUtil;
import dao.Interfaces.ITypeHebergementDAO;

public class TypeHebergementDAO implements ITypeHebergementDAO {
	/*
	public TypeHebergementDAO() {
	}

	public List<TypeHebergement> selectAll() {
		List<TypeHebergement> listeTransport = new ArrayList<TypeHebergement>();

		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction tx = session.beginTransaction();

		listeTransport.addAll(session.createQuery("from TypeHebergement").list());

		session.flush();
		tx.commit();
		session.close();

		return listeTransport;
	}

	public long insert(Transport t) {
		Transport transportTemp = t;
		Long msgId;

		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction tx = session.beginTransaction();

		msgId = (Long) session.save(transportTemp);

		session.flush();
		tx.commit();
		session.close();
		
		return msgId;
	}
	
	public int delete(Transport t) {
		Transport transportTemp = t;
		int retour;
		
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction tx = session.beginTransaction();
		
		retour = session.createQuery("delete from Transport where type='" + transportTemp.getType() + "'").executeUpdate();

		session.flush();
		tx.commit();
		session.close();
		
		return retour;
	}
	
	public Transport getByType(String type) {
		Transport transportTemp = new Transport();

		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction tx = session.beginTransaction();

		transportTemp = (Transport) session.createQuery("from Transport where type='" + type + "'").list().get(0);

		session.flush();
		tx.commit();
		session.close();

		return transportTemp;
	}*/
}
